import mockApi from "@/api/mockApi";
import type {ContractForm} from '@/types/req/contractForm'
import type {ContractQueryForm} from '@/types/req/contractQueryForm'
import type {Contract} from '@/types/resp/contract'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";

export default class contractApi {
  static contracts: Contract[] = [
    {"id":1,"candidateId":3,"candidateName":"王强","contractSignDate":"2023-10-22","contractType":30,"effectiveDate":"2024-01-01","expiryDate":"2026-12-31","state":20,"workLocation":"上海市浦东新区张江高科技园区","workingHours":"09:00-18:00","jobDescription":"负责环保项目的设计、实施及技术支持，确保项目符合环保标准","createTime":"2024-02-06 22:24:17","modifyTime":"2024-02-21 22:24:17"},
    {"id":2,"candidateId":2,"candidateName":"陈静","contractSignDate":"2023-06-09","contractType":20,"effectiveDate":"2023-07-01","expiryDate":"2023-12-31","state":30,"workLocation":"北京市海淀区中关村大街1号","workingHours":"09:30-17:30","jobDescription":"协助财务部完成日常账务处理及报表编制","createTime":"2024-07-24 22:24:17","modifyTime":"2024-03-12 22:24-17"},
    {"id":3,"candidateId":1,"candidateName":"张伟","contractSignDate":"2023-11-05","contractType":10,"effectiveDate":"2023-11-06","expiryDate":"2024-05-05","state":30,"workLocation":"深圳市南山区科技园","workingHours":"09:00-18:00","jobDescription":"负责软件系统的设计、开发及维护，编写高质量代码并解决技术问题","createTime":"2024-10-16 22:24:17","modifyTime":"2024-10-16 22:24:17"},
    {"id":4,"candidateId":4,"candidateName":"李娜","contractSignDate":"2023-01-21","contractType":30,"effectiveDate":"2023-02-01","expiryDate":"2026-01-31","state":20,"workLocation":"北京市海淀区中关村大街1号","workingHours":"09:30-17:30","jobDescription":"负责财务数据分析、预算编制及成本控制，提供决策支持","createTime":"2024-05-14 22:24:17","modifyTime":"2024-08-19 22:24:17"},
    {"id":5,"candidateId":2,"candidateName":"陈静","contractSignDate":"2023-03-23","contractType":30,"effectiveDate":"2023-04-01","expiryDate":"2026-03-31","state":20,"workLocation":"成都市高新区天府大道","workingHours":"09:00-18:00","jobDescription":"负责市场调研、品牌推广及销售策略制定，带领团队完成销售目标","createTime":"2024-06-10 22:24:17","modifyTime":"2024-03-22 22:24:17"},
    {"id":6,"candidateId":3,"candidateName":"王强","contractSignDate":"2023-03-18","contractType":30,"effectiveDate":"2023-04-01","expiryDate":"2026-03-31","state":20,"workLocation":"上海市浦东新区张江高科技园区","workingHours":"09:00-18:00","jobDescription":"负责环保项目的整体规划、执行及交付，协调团队资源并确保项目按时完成","createTime":"2024-09-02 22:24:17","modifyTime":"2024-10-13 22:24:17"},
    {"id":7,"candidateId":1,"candidateName":"张伟","contractSignDate":"2023-11-06","contractType":20,"effectiveDate":"2023-11-07","expiryDate":"2024-05-06","state":30,"workLocation":"深圳市南山区科技园","workingHours":"09:00-18:00","jobDescription":"协助开发团队完成软件系统的设计与开发，学习并应用最新技术","createTime":"2024-04-28 22:24:17","modifyTime":"2024-11-06 22:24:17"}
  ]

  static async save (contractForm: ContractForm): Promise<Result<void>> {
    console.log('contractApi save params', contractForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (contractQueryForm: ContractQueryForm): Promise<Result<Page<Contract>>> {
    console.log('contractApi find params', contractQueryForm)
    let filteredContracts = contractApi.contracts
    if (contractQueryForm.candidateId) {
      filteredContracts = contractApi.contracts.filter(contract => contract.candidateId === contractQueryForm.candidateId);
    }
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(filteredContracts)
    return response.data
  }

  static async findById (id: number): Promise<Result<Contract>> {
    console.log('contractApi findById id', id)
    let target = {}
    for (const a of contractApi.contracts) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<Contract> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('contractApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}